 /*
*Author:
*   fs
*   sjtu_fs@outlook.com
*   www.github.com/sjtufs
*
*   File:homework3_generator.cpp
*   Create Date:Fri 07 Jun 2013 09:40:48 PM CST
*/

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<cmath>
#include<memory.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define dimension (1000)
#define number (60)
int  project;

struct point
{
	double x[dimension+1];
}p[number+1];

int hash[10001];
double original_dis[1000][1000],projected_dis[1000][1000],error,kbid;

double sqr(double x)
{
	return x*x;
}

double dis(point p1,point p2,int dim)
{
	double sum=0.0;
	for(int i=0;i<dim;i++)
		sum+=sqr(p1.x[i]-p2.x[i]);
	return sqrt(sum);
}

int main()
	{
    //srand(time(NULL));
	freopen("hw3output","w",stdout);
	for(int i=0;i<number;i++)
	{
		double sum=0.0;
		for(int j=0;j<dimension;j++)
		{
			int sign=rand()%2;
			if(sign) p[i].x[j]=-rand();
			else p[i].x[j]=rand();
			sum+=sqr(p[i].x[j]);
		}
		sum=sqrt(sum);
		for(int j=0;j<dimension;j++)
			p[i].x[j]=p[i].x[j]/sum*100;
	}
	
	point o;
	for(int i=0;i<dimension;i++) o.x[i]=0;
	for(int i=0;i<number;i++)
		for(int j=i+1;j<number;j++)
		{
			original_dis[i][j]=original_dis[j][i]=dis(p[i],p[j],dimension);
		}
	/*
	for(int i=0;i<number;i++)
	{
		for(int j=i+1;j<number;j++)
			printf("%.2f \n",original_dis[i][j]);
	}	
	cout<<endl;
	*/
	int pro[20]={100,50,10,5,4,3,2,1};
	
	for(int ij=0;ij<8;ij++)
	{
	project=pro[ij];
	double kbid=(project+0.0)/dimension;
	kbid=sqrt(kbid);
	cout<<'\t'<<project<<'\t'/*<<kbid*/<<endl;
	error=0.0;
	for(int i=0;i<number;i++)
		for(int j=0;j<number;j++)
		{
			projected_dis[i][j]=projected_dis[j][i]=dis(p[i],p[j],project);
			error+=sqr((original_dis[i][j]*kbid-projected_dis[i][j]));
		}
	//for(int i=0;i<number;i++)
	//	for(int j=i+1;j<number;j++)
	//		printf("%.2f\n",projected_dis[i][j]/kbid);
	cout<<error<<endl;
	}
	return 0;
	}


